from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Shui
from .serializers import ShuiSER
# Create your views here.

class ShuiView(APIView):
    def get(self,request):
        title = Shui.objects.all()
        see = ShuiSER(title,many=True)
        s = see.data
        return Response({'data':s})
        # pass
    def post(self,requset):
        data = requset.data

        ser = ShuiSER(data=data)
        if ser.is_valid():
            code = 200
            msg = 'successful'
            ser.save()
        else:
            code = 500
            msg = 'fales'
        return Response({'code':code,'msg':msg})
